<template>
  <div>
    <div class="layui-container fly-marginTop">
      <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user">
          <ul class="layui-tab-title">
            <li><router-link :to="{ name: 'login' }">登录</router-link></li>
            <li class="layui-this">
              <router-link :to="{ name: 'forget' }">找回密码</router-link
              ><!--重置密码-->
            </li>
          </ul>
          <div
            class="layui-form layui-tab-content"
            id="LAY_ucm"
            style="padding: 20px 0"
          >
            <div class="layui-tab-item layui-show">
              <!-- 重置密码 -->
              <!--
          <div class="fly-msg">{{d.username}}，请重置您的密码</div>
          <div class="layui-form layui-form-pane"  style="margin-top: 30px;">
            <form action="/user/repass" method="post">
              <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="L_pass" name="pass" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
              </div>
              <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="L_repass" name="repass" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label for="L_vercode" class="layui-form-label">人类验证</label>
                <div class="layui-input-inline">
                  <input type="text" id="L_vercode" name="vercode" required lay-verify="required" placeholder="请回答后面的问题" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid">
                  <span style="color: #c00;">{{d.vercode}}</span>
                </div>
              </div>
              <div class="layui-form-item">
                <input type="hidden" name="username" value="{{d.username}}">
                <input type="hidden" name="email" value="{{d.email}}">
                <button class="layui-btn" alert="1" lay-filter="*" lay-submit>提交</button>
              </div>
            </form>
          </div>


          <div class="fly-error">该重置密码链接已失效，请重新校验您的信息</div>
          <div class="fly-error">非法链接，请重新校验您的信息</div>
          -->

              <div class="layui-form layui-form-pane">
                <form method="post">
                  <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">邮箱</label>
                    <ValidationProvider
                      rules="required|email"
                      v-slot="{ errors }"
                      name="email"
                    >
                      <div class="layui-input-inline">
                        <input
                          type="text"
                          name="email"
                          v-model="member.email"
                          placeholder="请输入邮箱"
                          autocomplete="off"
                          class="layui-input"
                        />
                      </div>
                      <div class="layui-form-mid">
                        <span style="color: #c00">
                          {{ errors[0] }}
                        </span>
                      </div>
                    </ValidationProvider>
                  </div>
                  <div class="layui-form-item">
                    <label for="L_captcha" class="layui-form-label"
                      >验证码</label
                    >
                    <ValidationProvider rules="required|min:4" v-slot="{errors}" name="captcha">
                      <div class="layui-input-inline">
                        <input
                          type="text"
                          name="captcha"
                          v-model="captcha"
                          placeholder="请输入验证码"
                          autocomplete="off"
                          class="layui-input"
                        />
                      </div>
                      <div class="captchaCode layui-form-mid">
                        <img
                          @click="getCaptchaCode"
                          id="captchaCode"
                          alt="验证码"
                        />
                      </div>
                      <div class="layui-form-mid">
                        <span style="color: #c00">
                          {{errors[0]}}
                        </span>
                      </div>
                    </ValidationProvider>
                  </div>
                  <div class="layui-form-item">
                    <button
                      type="button"
                      class="layui-btn"
                      @click="sendEmail()"
                    >
                      发送邮件
                    </button>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import moment from "moment";
import {sendEmailAxios} from '@/api/login'
import { ValidationProvider } from "vee-validate";
export default {
  name: "Forget",
  components: { ValidationProvider },
  data() {
    return {
      captcha: "",
      member: {
        name: "",
        loginName: "",
        email: "",
        imgCodeToken: "",
        to: "",
        subject: "",
        url: "",
        expireDate: "",
      },
    };
  },
  mounted() {
    this.getCaptchaCode();
  },
  methods: {
    getCaptchaCode() {
      this.member.imgCodeToken = Tool.get8UUID(8);
      $("#captchaCode").attr(
        "src",
        process.env.VUE_APP_SERVER +
          "/business/member/captcha/code/" +
          this.member.imgCodeToken
      );
    },
    sendEmailAxios(){

    },
    // sendEmail() {
    //   this.member.name = "刘先生";
    //   this.member.imgCodeToken = this.captcha;
    //   this.member.to = this.member.email;
    //   this.member.subject =
    //     "你好开发者！《cevent-一刀coder-社区综合服务平台》重置密码";
    //   this.member.url = "http://localhost:8081";
    //   //30分钟有效
    //   this.member.expireDate = moment()
    //     .add(30, "minutes")
    //     .format("YYYY-MM-DD HH:mm:ss");
    //   this.$axios
    //     .post(
    //       process.env.VUE_APP_SERVER + "/system/member/sendHtmlMail",
    //       this.member
    //     )
    //     .then((response) => {
    //       let resp = response.data;
    //       if (resp.success) {
    //         console.log("发送邮件成功：", resp, "发送内容：", this.member);
    //       }
    //     });
    // },
    sendEmail() {
      this.member.name = "刘一刀先生";
      this.member.imgCodeToken = this.captcha;
      this.member.to = this.member.email;
      this.member.subject =
        "你好开发者！《cevent-一刀coder-社区综合服务平台》重置密码";
      this.member.url = "http://localhost:8081";
      //30分钟有效
      this.member.expireDate = moment()
        .add(30, "minutes")
        .format("YYYY-MM-DD HH:mm:ss");
      sendEmailAxios
        (
          this.member
        )
        .then((response) => {
          if (response.success) {
            console.log("发送邮件成功：", resp, "发送内容：", this.member);
          }
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.layui-form-mid {
  margin-top: -8px;
}
.captchaCode {
  cursor: pointer;
}
</style>